package Thread;

class MyThread1 extends Thread{
    @Override
    public void run() {
        System.out.println("hello  t");
    }
}
public class Demo1 {
    public static void main1(String[] args) {
        Thread t = new MyThread1();
        t.isAlive();
        t.start();
        t.isAlive();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t.setDaemon(true);
        System.out.println("是否是后台线程 "+ t.isDaemon());

    }
    public static void main2(String[] args) {
        int count = 0 ;
        Thread t = new Thread(()->{
            while (true){
                System.out.println(count);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
            }
            }
        },"猪猪侠");
     //   count = 5;
        //t.setDaemon(true);
        t.start();

    }
static Object object = new Object();
    public static void main3(String[] args) {
        Thread t1 = new Thread(()->{
            synchronized (object){
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("我是t1");
            }
        });

        Thread t2 = new Thread(()->{
            synchronized (object){
                object.notify();

                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("线程2");

            }
        });
        t1.start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t2.start();
    }
}
